package com.zhangyx.crawler.comm;

import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;

public class CacheUtil {
    public static BlockingQueue<String> queue = new LinkedBlockingQueue();
    private static BlockingQueue<String> proxyQueue = new LinkedBlockingQueue();
    private static BlockingQueue<String> webTapQueue = new LinkedBlockingQueue();
    private static Map<String, String> map = new ConcurrentHashMap<String, String>();
    static {
        proxyQueue.add("https://app-zhangyuxin1111-1.appspot.com/");
        proxyQueue.add("https://app-zhangyuxin1111-2.appspot.com/");
        proxyQueue.add("https://app-zhangyuxin1111-3.appspot.com/");
        proxyQueue.add("https://app-zhangyuxin1111-4.appspot.com/");
        proxyQueue.add("https://app-zhangyuxin1111-5.appspot.com/");
        proxyQueue.add("https://app-zhangyuxin1111-6.appspot.com/");
        proxyQueue.add("https://app-zhangyuxin1111-7.appspot.com/");
        proxyQueue.add("https://app-zhangyuxin1111-8.appspot.com/");
        proxyQueue.add("https://app-zhangyuxin1111-9.appspot.com/");
        proxyQueue.add("https://app-zhangyuxin1111-10.appspot.com/");
        proxyQueue.add("https://app-zhangyuxin1111-11.appspot.com/");
        proxyQueue.add("https://app-zhangyuxin1111-12.appspot.com/");
        proxyQueue.add("https://app-zyx-1.appspot.com/");
        proxyQueue.add("https://app-zyx-2.appspot.com/");
        proxyQueue.add("https://proxy-liepin.appspot.com/");
        proxyQueue.add("https://proxy-liepin-s1.appspot.com/");
        proxyQueue.add("https://zyxgfw-980.appspot.com/");
        proxyQueue.add("https://zyxgfw01.appspot.com/");
        proxyQueue.add("https://liepin201701-1.appspot.com/");
        proxyQueue.add("https://liepin201701-2.appspot.com/");
        proxyQueue.add("https://liepin201701-3.appspot.com/");
        proxyQueue.add("https://liepin201701-4.appspot.com/");
        proxyQueue.add("https://liepin201701-5.appspot.com/");
        proxyQueue.add("https://liepin201701-6.appspot.com/");
        proxyQueue.add("https://liepin201701-7.appspot.com/");
        proxyQueue.add("https://liepin201701-8.appspot.com/");
        proxyQueue.add("https://liepin201701-9.appspot.com/");
        proxyQueue.add("https://liepin201701-10.appspot.com/");
        proxyQueue.add("https://liepin201701-11.appspot.com/");
        proxyQueue.add("https://liepin201701-12.appspot.com/");
    }
    public static String getUrl() {
        String ret = null;
        try {
            ret = queue.take();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ret;
    }
    public static void addTap(String handle) {
        webTapQueue.add(handle);
    }

    public static String getTapHandle() {
        String ret = null;
        try {
            ret = webTapQueue.take();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ret;
    }

    public static void keepUrl(String str) {
        queue.add(str);
    }

    public static String getProxyUrl() {
        String ret = null;
        try {
            ret = proxyQueue.take();
            proxyQueue.add(ret);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ret;
    }

    public static void set(String key, String value) {
        map.put(key, value);
    }

    public static String get(String key) {
        String ret = null;
        try {
            ret = map.get(key);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ret;
    }

    public static boolean isExist(String key) {
        return map.containsKey(key);
    }
}
